import { Button, message, Popconfirm } from "antd";
import { DeleteOutlined } from "@ant-design/icons";

export default (removeFunc, record, actionRef, params = {},cb) => {
  const handleRemove = async (row) => {
    const postData = {
      ids: params?.ids || row.id,
      ...params,
    }; // 传了params则取，不传取默认的
    const res = await removeFunc(postData);
    if (res.code == 200) {
      message.success("删除成功");
      actionRef?.current.reload();
      cb && cb();
    }
  };

  return (
    <Popconfirm
      key="remove"
      title="确定删除?"
      onConfirm={() => handleRemove(record)}
    >
      <Button type="primary" danger={true}>
        {!record && <DeleteOutlined />}
        删除
      </Button>
    </Popconfirm>
  );
};
